package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

// 持久层
@Mapper
public interface EmpMapper {

    // @Select("select emp.*, dept.name deptName from emp left outer join dept on emp.dept_id = dept.id limit #{offset}, #{pageSize};")
    // List<Emp> list(Integer offset, Integer pageSize);
    //
    // @Select("select count(*) from emp left outer join dept on emp.dept_id = dept.id;")
    // long count();

    // 使用分页插件
    // @Select("select emp.*, dept.name deptName from emp left outer join dept on emp.dept_id = dept.id")
    Page<Emp> list(EmpQueryParam param);

    // 添加数据SQL语句: insert into 表名 (字段名1, 字段名2) values (值1, 值2);
    // useGeneratedKeys = true: 获取新增数据的id,  keyProperty = "id": 类中保存主键的成员变量名
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp values (null, #{username}, null, #{name}, #{gender}, #{phone}, #{job}, #{salary}, #{image}, #{entryDate}, #{deptId}, #{createTime}, #{updateTime});")
    void insert(Emp emp);

    // 根据员工id批量删除员工基本信息
    void deleteByIds(Integer[] ids);


    Emp getById(Integer id);

    void update(Emp emp);

    /**
     * 根据账号密码登录
     * @param emp
     * @return
     */
    @Select("select * from emp where username=#{username} and password = #{password};")
    Emp getByUsernameAndPassword(Emp emp);

    @Select("select * from emp;")
    List<Emp> getEmpList();
}
